#define DEBUG
#include <cstdio>

using namespace std;

typedef long long ll;

const int maxn=200000, mods=1000000007;

int room[maxn+1], desk[maxn+1];
ll circle[maxn+1], link[maxn+1][2];
bool mark[maxn+1];

ll run(int o) {
  bool cir=true;
  int len=0, col;
  for (; !mark[o]; ) {
    mark[o] = true;
    if (room[o]) {
      col = 0, len++;
      o = room[o];
      room[o] = room[room[o]] = 0;
    } else if (desk[o]) {
      col = 1, len++;
      o = desk[o];
      desk[o] = desk[desk[o]] = 0;
    } else {
      cir = false;
      break;
    }
  }
  if (cir) {
    return circle[len]=(circle[len]+len)%mods;
  } else {
    if (len%2) {
      return link[len][col]=(link[len][col]+2)%mods;
    } else {
      return link[len][0]=(link[len][0]+1)%mods;
    }
  }
}

int main() {
  freopen("mate.in", "r", stdin);
  freopen("mate.out", "w", stdout);

  int n, m1, m2;
  scanf("%d %d %d", &n, &m1, &m2);
  for (int i=1; i<=m1; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    room[u] = v, room[v] = u;
  }
  for (int i=1; i<=m2; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    desk[u] = v, desk[v] = u;
  }

  ll ans=1;
  //Point
  for (int i=1; i<=n; i++) {
    if (!desk[i] && !room[i] && !mark[i]) {
      mark[i] = true;
      circle[0] = (circle[0]+1)%mods;
      ans = ans*circle[0]%mods;
    }
  }

  //Link
  for (int i=1; i<=n; i++) {
    if (!mark[i] && ((!desk[i])^(!room[i]))) {
      ans = ans*run(i)%mods;
    }
  }

  //Circle
  for (int i=1; i<=n; i++) {
    if (!mark[i]) {
      ans = ans*run(i)%mods;
    }
  }

  printf("%lld", ans);

  fclose(stdin);
  fclose(stdout);
  return 0;
}
